package com.cskaoyan.servlet;

import com.cskaoyan.bean.PageData;
import com.cskaoyan.bean.ProfileLsnoticeParameter;
import com.cskaoyan.bean.vo.BaseRespVo;
import com.cskaoyan.common.CommonServlet;
import com.cskaoyan.model.MarketNotice;
import com.cskaoyan.service.ProfileService;
import com.cskaoyan.service.impl.ProfileServiceImpl;
import com.cskaoyan.utils.JacksonUtil;
import org.apache.commons.beanutils.BeanUtils;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
import java.util.Map;


@WebServlet("/admin/profile/*")
public class AdminProfileServlet extends CommonServlet {
    ProfileService profileService = new ProfileServiceImpl();

    public BaseRespVo lsnotice(HttpServletRequest request, HttpServletResponse response) throws InvocationTargetException, IllegalAccessException {
        Map<String, String[]> parameterMap = request.getParameterMap();
        ProfileLsnoticeParameter lsnoticeParameter = new ProfileLsnoticeParameter();
        BeanUtils.copyProperties(lsnoticeParameter,parameterMap);
        List<MarketNotice> noticeList = profileService.lsnotice(lsnoticeParameter);
        PageData data = PageData.list(noticeList);
        return BaseRespVo.ok(data);
    }

    public BaseRespVo notice(HttpServletRequest request, HttpServletResponse response) {
        return BaseRespVo.ok(0);
    }

    public BaseRespVo catnotice(HttpServletRequest request, HttpServletResponse response) throws IOException {
        String jsonStr = request.getReader().readLine();
        MarketNotice notice = JacksonUtil.read(jsonStr, MarketNotice.class);
        MarketNotice readNotice = profileService.catnotice(notice);
        return BaseRespVo.ok(readNotice);
    }
}
